import { 
  util,
  dialog,
  storage,
  api,
  forms
} from '../../../js/util'; 
import {
  router
} from '../../../js/router';
import {
  cashier,payment
} from '../../../js/modules/pay';
import { $ecCountDown } from '../../../components/index'
import {
  orderPay
} from '../../../js/modules/pay';
import authorize from '../../../js/modules/authorize.js';
import BasePage from '../../../js/common/base-page'
const info = require("../../../js/modules/info.js");
import {upload} from '../../../js/modules/material.js'
import { alert, confirm, isEmpty } from '../../../js/newUtil';
var app = getApp();

BasePage({
  pageKey:"cashier",
  validateLogin: false,
  /**
   * 页面的初始数据
   */
  data: { 
    showModalStatus: false,
    outtime: false ,    //支付是否过期
    payToken: "",
    payPassword:'',
    selectedPayId:0, 
    selectedPayKindId:0,//选中的支付方式对象 
    selectedPayIcon:'',
    oderData: [],
    payData: [],
    pagetype:'order',
    EnbBalance:0, //预存款弹出层的可用余额金额显示
    CreditBalance: 0,// 授信支付弹出层的可用额度金额显示
    PayTypes:[],//支付方式
    isSuccess:false,
    isSubmitOrder:false,
    verifyMobileShadow:false, //验证手机弹层
    forms:{
      Mobile:{
        value: "",
        validate: "isnull||mobile",
        error: "请输入正确的手机号"
      },
      PicVerifyCode: {
        value: "",
        validate: "isnull",
        error: "请输入正确的校验码"
      },
      ValidateCode: {
        value: "",
        validate: "isnull",
        error: "请输入正确的短信校验码"
      },
    },
    isCancelOrder:false,   //是否取消过微信支付（确保取消后不自动支付）
    OrderInfo: '',
    voucher: [],
    imgDomain: api.imgDomain,
    cashier:'',
    Currency:'',//货币符号
    microPayData: {
      banner: [],
      banks: {list:[]},
      slogan: {}
    },
    isShowItems: false //是否显示明细
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 如果存在openid这个参数，代表是从webview跳转过来的支付
    if (options.openid) {
      this.webWxPay(options.openid)
      return
    }
    // 重置判断支付成功的循环用的flag
    app.globalData.flag = false
    var paytoken=options.paytoken;
    var recordData = options.recordData;
    var payStatus = options.payStatus;
    var that=this;
    that.validateLogin = options.cashier == 'alone'?false:true;
    that.setData({
      isSuccess: payStatus == 1,
      cashier: options.cashier
    })
    console.log(paytoken,'----paytoken',options.cashier);
    if(paytoken==undefined||paytoken==""){
      orderPay.findPayOrderData(recordData, "paySuccess", function (recordToken) {
        that.data.payToken = recordToken;
        that.initOrderData();
        // that.initPayData(); 
      }, payStatus!=0);
    }
    else{
      that.data.payToken = paytoken;
      that.initOrderData();
      // that.initPayData(); 
    }
  },
  /**初始化订单数据 */
  initOrderData(){
    var that = this;
    cashier.loadCashierOrderData(that.data.payToken, function (reData){ 
      console.log('=====1',reData);
      that.setData({
        oderData: reData
      });
      that.initPayData(reData);
    });
  },
  /*初始化支付方式数据 */
  initPayData(reData){
    var that = this;
    cashier.loadCashierPayData(that.data.payToken,that.validateLogin,reData, function (reData) { 
      that.setCountdown(reData.InvalidTime);
      let hasMicroPay = false;
      reData.Data.map((item)=>{
        item.Checked=false;
        if (!hasMicroPay && item.KindId == 51) {
            hasMicroPay = true;
        }
      });
      if (reData.Data.length == 1) {
        reData.Data[0].Checked = true;
      }
      if (hasMicroPay) {
        that.getMicroPayData();
      }
      that.setData({ payData: reData },()=>{
        if (reData.Data.length==1 && that.data.isCancelOrder==false){
          let list = reData.Data || [{}]
          if (list[0].KindId != 51) {
            that.changePayWay({ detail: { value: 0 } })
          } else {
            let pay = list[0]
            if (!isEmpty(pay)) {
              that.setData({
                selectedPayId: pay.PayId, 
                selectedPayKindId: pay.KindId,
                selectedPayIcon:pay.Icon
              });
            }
          }
        }
      }); 
    });
  },
  getMicroPayData(){
    let that = this;
    cashier.getMicroPayData(function(res){
      if (res && res.statusCode == 200 && res.data.code == 200) {
        let microPayData = {
          banner: JSON.parse(res.data.data.banner),
          banks: JSON.parse(res.data.data.banks),
          slogan: JSON.parse(res.data.data.slogan)
        };
        that.setData({microPayData: microPayData});
      }
    });
  },
  refreshPage:function(){
    this.initOrderData();
  },
  /**
 * 倒计时
 *  */
  setCountdown(time) {
    this.c1 = new $ecCountDown({
      date: time,
      render(date) {
        const days = this.leadingZeros(date.days, 2)
        const hours = this.leadingZeros(date.hours, 2)
        const min = this.leadingZeros(date.min, 2)
        const sec = this.leadingZeros(date.sec, 2)

        this.setData({
          c1: days,
          c2: hours,
          c3: min,
          c4: sec,
          c0: (date.days == 0 && date.hours == 0 && date.min == 0 && date.sec == 0)
        })
      },
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.hideModal();
    // this.initOrderData();
    // this.initPayData(); 
    this.setData({
      Currency:api.Currency || '￥'
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
	this.cancelPayTimer();
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }, 
  /**
   * 支付方式选择
   */
  changePayWay: function (evt) { 
    let idx = evt.detail.value;
    let {payData}=this.data;
    let pay = payData.Data[idx];
    this.setData({
      selectedPayId: pay.PayId, 
      selectedPayKindId: pay.KindId,
      selectedPayIcon:pay.Icon
    });
    if (pay.KindId == 1) { 
      //判断预存款余额是否可用
      if (payData.IsEnough) {
        this.setData({
          EnbBalance: payData.EnbBalance 
        },()=>{
          if(payData.UsePassword){
            //获得发送短信组件
            this.smsVerifyCode = this.selectComponent("#ValidateCode");
            if(this.smsVerifyCode){
            //设置回调
            this.smsVerifyCode.data.callback = this.getSmsCode;
            }
          }
        });
        this.checkPassword()
        dialog.showModal(this, 'showModalStatus')
      }
    }
    else if (pay.KindId == 17) {
      this.showRemit(pay.PayId, evt);
    }
    else if (pay.KindId==18){ 
      this.setData({
        CreditBalance: this.data.payData.CreditBalance
      },()=>{
        if(payData.UsePassword){
          //获得发送短信组件
          this.smsVerifyCode = this.selectComponent("#ValidateCode");
          if(this.smsVerifyCode){
          //设置回调
          this.smsVerifyCode.data.callback = this.getSmsCode;
          }
        }
      });
      dialog.showModal(this, 'showModalStatus')
    }else if (pay.KindId == 3 || pay.KindId == 31 || pay.KindId == 66) {
      this.wechatPay();
    }else if(pay.KindId == 51){
      this.tenPay();
    }
  },

  /**验证手机弹层 */
  showVerifyMobile:function(){
    let that = this;
    this.setData({
      verifyMobileShadow:true
    },function(){
      //获得图片验证码组件
      that.picVerifyCode = that.selectComponent("#PicVerifyCode");
      //设置回调
      that.picVerifyCode.data.callback = info.getPicVerifyCode;
      //调用一次图片验证码
      that.picVerifyCode.bindPicVerifyCode();
      //获得发送短信组件
      that.smsVerifyCode = that.selectComponent("#ValidateCode");
      //设置回调
      that.smsVerifyCode.data.callback = that.bindSmsVerifyCode;
    });
  },
  hideVerifyMobile:function(){
    this.setData({
      verifyMobileShadow:false
    });
  },
  /**
   * 表单值绑定
   */
  bindFormValue: function (e) {
    e = e.detail;
    this.data.forms[e.target.id].value = e.detail.value;
  },
  /*
  发送短信验证码
   */
  bindSmsVerifyCode: function(callback) {
    let that = this;
    let {payData,forms} = that.data;
    if(payData.Mobile==''&&forms.Mobile.value==''){
      util.alert('您没有预留手机号，请输入');
      return;
    }
    if (payData.Mobile==''&&!forms.validate(forms.Mobile.value)){
      util.alert('请输入正确的手机号');
      return;
    }
    var picvalidatecode = this.data.forms.PicVerifyCode.value;
    if (picvalidatecode.length == 0) {
      util.alert("请先输入4位验证码");
      return;
    }
    var codeToken = storage.get("pic_verify_code");
    if (codeToken == undefined || codeToken.length == 0) {
      util.alert("图片验证码过期");
      return;
    }

    var data = {
      verifyType: 1,//验证形式，1:先验证图片码 0:无需前置验证
      verifyCode: picvalidatecode,
      codeToken: codeToken
    };
    if(payData.Mobile==''){
      data.mobile = forms.Mobile.value
    }else{
      data.SecurityToken = payData.SecurityToken
    }
    info.sms.getSmsVerifyCode(data, "info.smscode.get", function (content) {
      if (callback && typeof (callback) == "function") {
        callback(content);
      }
    });
  },
  /*
  发送短信验证码
   */
  getSmsCode: function(callback) {
    let that = this;
    let {payData,forms,payToken} = that.data;
    if(payData.Mobile==''&&forms.Mobile.value==''){
      util.alert('您没有预留手机号，请输入');
      return;
    }
    var data = {
      recordToken: payToken,
      mobileToken: payData.SecurityToken,
      mobileCode: payData.Mobile,
    };
    info.sms.getSmsVerifyCode(data, "payment.cashier.sendsmscode", function (content) {
      if (callback && typeof (callback) == "function") {
        callback(content);
      }
    });
  },
  /**
   * 立即验证
   */
  verifyMobile:function(){
    let that = this;
    let {payData,forms} = that.data;
    if(payData.Mobile==''&&forms.Mobile.value==''){
      util.alert('您没有预留手机号，请输入');
      return;
    }
    if (payData.Mobile==''&&!forms.validate(forms.Mobile.value)){
      util.alert('请输入正确的手机号');
      return;
    }
    var picvalidatecode = forms.PicVerifyCode.value;
    if (picvalidatecode.length == 0) {
      util.alert("请先输入4位验证码");
      return;
    }
    var codeToken = storage.get("pic_verify_code");
    if (codeToken == undefined || codeToken.length == 0) {
      util.alert("图片验证码过期");
      return;
    }
    if(forms.ValidateCode.value == ''){
      util.alert("请输入手机验证码");
      return;
    }
    var entity = authorize.getEntity();
    var data = {
      UserFlag:entity.fkFlag,
      UserId:entity.fkId,
      MobileCode: forms.ValidateCode.value,
    }
    if(payData.Mobile==''){
      data.mobile = forms.Mobile.value,
      data.ValidateType = 'bind'
    }else{
      data.SecurityToken = payData.SecurityToken,
      data.ValidateType = 'valid'
    }
    cashier.verifyMobile(data,'Info.validate.mobile',function(content){
      console.log(content);
      util.alert("验证手机号成功");
      that.setData({
        verifyMobileShadow:false
      },function(){
        that.hideModal();
        that.initPayData();
      })
    })
  },
  /**显示转账汇款的弹出层*/ 
  showRemit(payId,evt){
    var that = this;
    cashier.showRemit(payId, function (res) {
      try {
        //预览图片
        //var content = res.KeyValue.replace(/lazy_src|src/ig, "viewpic=\"true\" src","");
        console.log(res.KeyValue,"ssss");
        that.setData({
          richtext_content: res.KeyValue
        })
      } catch (e) {

      }
      dialog.showModal(that, 'showModalStatus')
    }); 
  },
  /**
   * 解析tag事件
   */
  wxParseTagATap(e) {
    let event = e.detail.event || {currentTarget: {dataset: {src: ''}}}
    var url = event.currentTarget.dataset.src;
    router.navigate({
      path: "transfer",
      params: {
        thirdDomain: encodeURIComponent(url)
      }
    });
  },
  /**预览图片 */
  previewImage: function (e) {
    return;
    var current = e.target.dataset.src;
    wx.previewImage({
      current: current,
      urls: [current]
    })
  },
  hideModal(e){
    dialog.hideModal(this, 'showModalStatus')
  },
  /**设置支付密码 */
  passwordInputEvent: function (e) {
    this.setData({
      payPassword: e.detail.value
    });
  },

  /**预存款支付 */
  prestorePay(){
    if (this.data.isSubmitOrder) {
      return;
    }
    let that = this;
    let {payData,selectedPayId,payPassword,payToken,forms}=this.data;
    let mobileCode=forms.ValidateCode.value;
    if (payPassword == '') {
      util.tips("请输入支付密码");
      return;
    }
    if(payData.IsPhoneVerify&&payData.MobileValidated&&mobileCode==''){
      util.tips("请输入手机验证码");
      return;
    }
    this.setData({
      isSubmitOrder: true
    });

    let param = {
      payToken: payToken,
      payPassword: payPassword,
      payId: selectedPayId,
      mobileToken: payData.SecurityToken,
      mobileCode:mobileCode 
    };
    payment.prestorePay(param,function(res){
      that.setData({
        isSubmitOrder: false
      });
      if (res.Success) {
        router.redirect({
          path: "paySuccess",
          params: { paytoken: that.data.payToken,cashier:that.data.cashier }
        });
      }else {
        util.alert(payment.get_error_msg(res)||"支付失败");
      } 
    });
  },
  /**转账汇款 */
  remitPay(){
    var that=this;
    var image_list = that.data.OrderInfo;
    if (image_list != undefined && image_list.length != '') {
      payment.upload_voucher(that.data.payToken, image_list, function(){
        that.data.OrderInfo = image_list;
        let voucher=[];
        voucher.push(that.data.imgDomain + image_list);
        that.setData({
          OrderInfo: that.data.OrderInfo,
          voucher: voucher
        });
        router.redirect({
          path: "paySuccess",
          params: { paytoken: that.data.payToken,cashier:that.data.cashier }
        });
      });
    } else {
      router.redirect({
        path: "paySuccess",
        params: { paytoken: that.data.payToken,cashier:that.data.cashier }
      });
    }
  },
  /**
   * 点击查看凭证大图
   */
  showbigImg: function (event) {
    var index = event.currentTarget.dataset.index;
    var srcs = event.currentTarget.dataset.srcs;
    //图片预览
    wx.previewImage({
      current: srcs[index], // 当前显示图片的http链接
      urls: srcs // 需要预览的图片http链接列表
    })
  },
  /**
   * 付款成功
   */
  paySuccess: function () {
    wx.showToast({
      title: '支付成功',
      icon: 'success',
      duration: 2000
    })
  },
  /**
   * 付款失败
   */
  payFailed: function () {
    wx.showToast({
      title: '支付失败，请重试',
      icon: 'none',
      duration: 2000
    })
  },
  /**
   * 监听支付状态
   * 
   * 当为webview跳转后时，支付成功需要监听的是webview前的页面
   * 
   */
  startPayTimer: function () {
    var that = this;
    wx.showLoading({title: '等待支付结果'});
    let pages = getCurrentPages()
    let delta = -1
    let currentPage = pages[pages.length - 1]
    if (currentPage.options) {
      // 判断当前显示的页面是否为webview跳转的页面，如果是则需要返回值跳转前
      if (currentPage.options.openid) {
        for (let i = pages.length - 2; i >= 0; i--) {
          if (pages[i].route == 'packageCashier/pages/pay/pay') {
            delta = pages.length - i
            break;
          }
        }
      }
    }
    app.globalData.visitTimer = setInterval(()=>{
      // TODO 你需要无限循环执行的任务
      if(app.globalData.flag){
        that.cancelPayTimer();
        return;
      }
      payment.monitorPay(that.data.payToken, function(status) {
        if (status) {
          // 返回跳转前页面
          if (delta != -1) {
            wx.navigateBack({
              delta,
              success () {
                that.payComplete()
              },
              fail () {
                that.payComplete()
              }
            })
          } else {
            that.payComplete()
          }
        }
      }, "3.0");
    }, 2000)
    if(app.globalData.flag){
      app.globalData.flag = false;
      that.cancelPayTimer();
    }
  },
  /**
   * 支付成功后的方法
   */
  payComplete () {
    this.cancelPayTimer();
    app.globalData.flag = true;
    util.success("支付成功");
    router.redirect({
      path: "paySuccess",
      params: { paytoken: this.data.payToken,cashier:this.data.cashier }
    });
  },
  /**
   * 停止监听
   */
  cancelPayTimer: function () {
    wx.hideLoading();
    this.setData({ isSubmitOrder: false });
    if (app.globalData.visitTimer!=null) {
      clearInterval(app.globalData.visitTimer);
      app.globalData.visitTimer = null;
    }
  },
  /**微信支付 */
  wechatPay(){
    var that=this;
    let {selectedPayId,payToken}=that.data;
    if(selectedPayId<1){
      util.alert("网络繁忙，获取选中支付方式信息失败!");
      return;
    }
    if (this.data.isSubmitOrder){
      return;
    }
    this.setData({
      isSubmitOrder: true
    });
    var param = {
      recordToken: payToken,
      paymentId: selectedPayId, 
      TradeType: 0
    };
    var selfVal = {
      proprietorId:that.data.payData.ReceiveFKId, 
      fKId:that.data.payData.ReceiveFKId, 
      fKFlag:that.data.payData.ReceiveFKFlag,
      validateLogin:that.validateLogin
    }
    payment.wechatPay(param,selfVal,function(content){
      // 当传入scene==1时，不调取支付，改为跳转到客户的webview网页
      if (content.scene == 1) {
        let url = content.url || ''
        url = encodeURIComponent(url)
        wx.navigateTo({
          url: '/pages/common/medium/index?url='+ url
        })
        return
      }
      if (content.scene == 5 || content.scene == 6) {
        that.adaPay(content)
        return
      }
      payment.wxRequesPay(content, function(){
        that.startPayTimer();
      }, function(){
        that.setData({
          isSubmitOrder: false,
          isCancelOrder: true
        });
      });
    },function(){
      that.setData({
        isSubmitOrder: false,
        isCancelOrder: true
      });
    })
  },
  /**微信支付 */
  tenPay(){
    var that = this;
    let {selectedPayId,payToken}=that.data;
    if(selectedPayId<1){
      util.alert("网络繁忙，获取选中支付方式信息失败!");
      return;
    }
    var param = {
      payToken: payToken,
      payTypeId: '-1',
      payId: selectedPayId
    };
    if (this.data.isSubmitOrder) {
      return;
    }
    this.setData({
      isSubmitOrder: true
    });
    payment.cashierPay(param, function (res) {
      if (res.Success) {
        let content = res.Content || {};
        //半屏打开微企付小程序
        let obj = {
          appId: content.appId || 'wx2922b0afc7537485',
          path: content.redirect_url || '',
          envVersion: content.version || 'release',
          success: function(){
            that.startPayTimer();
          },
          fail: function(){
            that.setData({
              isSubmitOrder: false,
              isCancelOrder: true
            });
          }
        }
        if (wx.openEmbeddedMiniProgram) {
          wx.openEmbeddedMiniProgram(obj)
        } else {
          wx.navigateToMiniProgram(obj)
        }
      } else {
        that.setData({
          isSubmitOrder: false,
          isCancelOrder: true
        });
        util.alert(payment.get_error_msg(res)||"支付失败");
      }
    });
  },
  /**
   * 聚合支付
   */
  adaPay(content = {}) {
    let that = this
    let data = content.data || {}
    console.log('聚合支付', data)
    if (!isEmpty(data)) {
      // 跳转汇付小程序支付
      if (content.scene == 6) {
        wx.navigateToMiniProgram({
          appId: data.wx_app_id || 'wx1e18d140f890f2c5',
          path: data.miniapp_path || '',
          envVersion: data.version || 'release',
          success: function () {
            that.startPayTimer()
          },
          fail: function () {
            that.setData({
              isSubmitOrder: false,
              isCancelOrder: true
            })
          }
        })
        return
      }
      // 插件支付
      adapayPlugin.requestPay(data, function () {
        that.startPayTimer()
      }, function () {
        that.setData({
          isSubmitOrder: false,
          isCancelOrder: true
        })
      })
    } else {
      alert('支付信息错误，请稍后重试')
      that.setData({
        isSubmitOrder: false,
        isCancelOrder: true
      })
    }
  },
  /**
   * 解析数据直接调取支付
   * 
   * 某用户接入银行系统，需要跳转到网页后再跳回来并且支付，所以需要此方法
   * 
   * 支付失败后返回支付页面
   * 
   * 支付成功后也跳转回支付页面，并进行成功后的方法
   * 
   */
  webWxPay (data) {
    let that = this
    data = decodeURIComponent(data)
    let historyPayPage = null
    let pages = getCurrentPages()
    let delta = 1
    for (let i = pages.length - 2; i >= 0; i--) {
      if (pages[i].route == 'packageCashier/pages/pay/pay') {
        delta = pages.length - i - 1
        historyPayPage = pages[i]
        console.log(delta, historyPayPage)
        break;
      }
    }
    try {
      data = JSON.parse(data)
    } catch (err) {
      console.log('webWxPay error', err, data)
    }
    payment.wxRequesPay(data, function(){
      // 支付成功
      if (historyPayPage) {
        historyPayPage.startPayTimer()
      }
    }, function(){
      // 支付失败，返回提交支付页面
      if (historyPayPage) {
        historyPayPage.setData({
          isSubmitOrder: false,
          isCancelOrder: true
        })
        wx.navigateBack({
          delta
        })
      }
    })
  },
  /**确认支付 */
  confirmPay(evt){
    let { payData, selectedPayKindId, selectedPayIcon }=this.data;
    if (selectedPayKindId == 1) {
      if (!payData.IsEnough) {
        util.tips("预存款可用余额不足");
        return;
      }
      this.checkPassword()
      dialog.showModal(this, 'showModalStatus')
    } 
    if (selectedPayKindId == 17) {
      this.showRemit(this.data.selectedPayId)
    }
    if (selectedPayKindId == 3 || selectedPayKindId==31 || selectedPayKindId==66 || selectedPayIcon == 'wechat') {
      this.wechatPay();
    } 
    if (selectedPayKindId == 18) {
      dialog.showModal(this, 'showModalStatus')
    }
    if (selectedPayKindId == 51) {
      this.tenPay();
    }
  },
  /**授信支付 */
  creditPay(){
    var that = this;
    let {payData,forms,selectedPayId,payPassword,payToken}=that.data;
    let mobileCode=forms.ValidateCode.value;
    if(selectedPayId<1){
      util.alert("网络繁忙，获取选中支付方式信息失败!");
      return;
    }
    var param = {
      payToken: payToken,
      payPassword: payPassword,
      appliedId: selectedPayId,
      payId: selectedPayId,
      mobileToken: payData.SecurityToken,
      mobileCode: mobileCode 
    };
    if (this.data.isSubmitOrder) {
      return;
    }
    this.setData({
      isSubmitOrder: true
    });
    payment.creditPay(param, function (res) {
      that.setData({
        isSubmitOrder: false
      });
      if (res.Success) {
        router.redirect({
          path: "paySuccess",
          params: { paytoken: that.data.payToken ,cashier:that.data.cashier}
        });
      } else {
        util.alert(payment.get_error_msg(res)||"支付失败");
      }
    });
  },
  /**
   * 上传
   */
  bindUploadEvent:function(){
    var that=this;
    wx.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      sourceType: ['album'],
      success: function (res) {
        var tempFilePaths = res.tempFilePaths;
        console.log(tempFilePaths,'==========');
        var data = {num:1008,type:1,tempFilePaths:tempFilePaths};
        upload.upload_image_server(data, function (image_list) {
          let voucher = []
          if (image_list.length==0){
            util.alert("上传失败");
            return;
          }
          that.data.OrderInfo = image_list;
          voucher.push(that.data.imgDomain + image_list);
          that.setData({
            OrderInfo: that.data.OrderInfo,
            voucher: voucher
          });
        })
      }
    });
    // upload.upload_image(1,function (image_list){
    //   let voucher=[];
    //   if (image_list.length==0){
    //     util.alert("上传失败");
    //     return;
    //   }
    //   that.data.OrderInfo = image_list;
    //   voucher.push(that.data.imgDomain + image_list);
    //   that.setData({
    //     OrderInfo: that.data.OrderInfo,
    //     voucher: voucher
    //   });
    //   // console.log(image_list,'------');
    // });

  },
  /**
   * 删除
   */
  onDelImageEvent(e){
    this.setData({
      OrderInfo: '',
      voucher: []
    })
  },
  toRecharge(){
    router.navigate({
      path: "recharge" 
    });
  },
  preventTouchMove() {

  },
  bindUnfold(e){
    this.setData({
      isShowItems: !this.data.isShowItems
    })
  },
  checkPassword () {
    let payData = this.data.payData || {}
    if (!payData.UsePassword) {
      confirm({
        content: '第一次使用预存款支付，需要您设置支付密码',
        confirmText: '去设置',
        success (res) {
          if (res.confirm) {
            router.navigate({
              path: 'payPwdModify',
              params: {
                editType: 'resetDefaultPassword'
              }
            })
          }
        }
      })
    }
  },
})